package com.aodesoft.power;

import java.lang.reflect.Method;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

public class ForwardLoginInterceptor extends MethodFilterInterceptor {
	private static final long serialVersionUID = 1L;
	/**
	 * 前台登陆拦截
	 * @author tang
	 * @date 2011-10-10
	 * @param invocation
	 * @return
	 * @throws Exception
	 */
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		Class<?> clzz=invocation.getAction().getClass();
		String methodName=invocation.getProxy().getMethod();
		System.out.print("前台拦截:"+clzz.getSimpleName()+"的"+methodName+"()方法");
		Method m= clzz.getMethod(methodName);
		FwdItp fwdItp = null;
		try {fwdItp=m.getAnnotation(FwdItp.class);} catch (Exception e) {}
		
		if(fwdItp!=null && fwdItp.value()==Itp.IN){
			System.out.println("  结果：拦截\n");
			return invocation.invoke();
		}else{
			System.out.println("  结果：放行\n");
			return invocation.invoke();
		}
		
		/*
		// 取得请求相关的ActionContext实例
		ActionContext ctx = invocation.getInvocationContext();
		Map session = ctx.getSession();
		HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
		if (session.get("forwardLogin") != null ) {
			return invocation.invoke();
		}
		ctx.put("url", request.getRequestURL().toString());
		return "forwardLogin";
		 */
	}
} 
